#include "MatchProcParamCollectResponsePanel.h"

#include "../../../../../mes/utils/TaskManager.h"

#include "../../../../models/MatchProcParamCollectData.h"
#include "../../../../models/CommonData.h"
#include "../../../../controller/SignalBus.h"

#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>

MatchProcParamCollectResponsePanel::MatchProcParamCollectResponsePanel(QWidget *parent)
    : QWidget{parent}
{

    connect(SignalBus::instance(),&SignalBus::sendMatchProcParamCollect,this,&MatchProcParamCollectResponsePanel::reciveData);
}

void MatchProcParamCollectResponsePanel::initWidget()
{

}

void MatchProcParamCollectResponsePanel::setupUi()
{

}

void MatchProcParamCollectResponsePanel::reciveData()
{
    TaskManager task(BaseData<CommonData>::execute(&CommonData::getNetwork));
    QString factoryNo = QString::fromStdString(BaseData<CommonData>::execute(&CommonData::getFactoryNo));
    QString transId = QString::fromStdString(BaseData<CommonData>::execute(&CommonData::getTransId));
    QString eventUser = QString::fromStdString(BaseData<CommonData>::execute(&CommonData::getEventUser));
    QString machineNo = QString::fromStdString(BaseData<CommonData>::execute(&CommonData::getMachineNo));
    QString pcu = QString::fromStdString(BaseData<MatchProcParamCollectData>::execute(&MatchProcParamCollectData::getPcu));
    std::list<Params> params = BaseData<MatchProcParamCollectData>::execute(&MatchProcParamCollectData::getParamList);
    QList<ParamList> paramList;
    QList<ParamInfo> paramInfo;
    for(const auto& item:params)
    {
        paramList.append({QString::fromStdString(item.key),QString::fromStdString(item.value),QString::fromStdString(item.seq),QString::fromStdString(item.location)});
    }

    paramInfo.append({pcu,paramList});

    auto response = task.MatchProcParamCollectPost(factoryNo,eventUser,machineNo,paramInfo);

    if(response!=nullptr)
    {
    }
    else
    {
        qDebug()<<tr("获取失败");
        // valueList["resultCode"]->setText(tr("获取失败"));
        // valueList["resultMsg"]->setText(tr("获取失败"));
    }
    BaseData<CommonData>::execute(&CommonData::getNetwork)->cancelTask(task.TaskId(task.MatchProcParamCollect()));

}
